namespace DotNetNuke.Common.Utilities
{
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Reflection;
    using System.Runtime.CompilerServices;

    public class Null
    {
        public static object GetNull(object objField, object objDBNull)
        {
            object GetNull = RuntimeHelpers.GetObjectValue(objField);
            if (objField == null)
            {
                return RuntimeHelpers.GetObjectValue(objDBNull);
            }
            if (objField is short)
            {
                if (Convert.ToInt16(RuntimeHelpers.GetObjectValue(objField)) == NullShort)
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
                return GetNull;
            }
            if (objField is int)
            {
                if (Convert.ToInt32(RuntimeHelpers.GetObjectValue(objField)) == NullInteger)
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
                return GetNull;
            }
            if (objField is float)
            {
                if (Convert.ToSingle(RuntimeHelpers.GetObjectValue(objField)) == NullSingle)
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
                return GetNull;
            }
            if (objField is double)
            {
                if (Convert.ToDouble(RuntimeHelpers.GetObjectValue(objField)) == NullDouble)
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
                return GetNull;
            }
            if (objField is decimal)
            {
                if (decimal.Compare(Convert.ToDecimal(RuntimeHelpers.GetObjectValue(objField)), NullDecimal) == 0)
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
                return GetNull;
            }
            if (objField is DateTime)
            {
                if (DateTime.Compare(Convert.ToDateTime(RuntimeHelpers.GetObjectValue(objField)).Date, NullDate.Date) == 0)
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
                return GetNull;
            }
            if (objField is string)
            {
                if (objField == null)
                {
                    return RuntimeHelpers.GetObjectValue(objDBNull);
                }
                if (objField.ToString() == NullString)
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
                return GetNull;
            }
            if (objField is bool)
            {
                if (Convert.ToBoolean(RuntimeHelpers.GetObjectValue(objField)) == NullBoolean)
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
                return GetNull;
            }
            if (objField is Guid)
            {
                Guid refStructHelperS1 = (Guid) objField;
                if (refStructHelperS1.Equals(NullGuid))
                {
                    GetNull = RuntimeHelpers.GetObjectValue(objDBNull);
                }
            }
            return GetNull;
        }

        public static bool IsNull(object objField)
        {
            if (objField != null)
            {
                if (objField is int)
                {
                    return objField.Equals(NullInteger);
                }
                if (objField is float)
                {
                    return objField.Equals(NullSingle);
                }
                if (objField is double)
                {
                    return objField.Equals(NullDouble);
                }
                if (objField is decimal)
                {
                    return objField.Equals(NullDecimal);
                }
                if (objField is DateTime)
                {
                    return Conversions.ToDate(objField).Date.Equals(NullDate.Date);
                }
                if (objField is string)
                {
                    return objField.Equals(NullString);
                }
                if (objField is bool)
                {
                    return objField.Equals(NullBoolean);
                }
                return ((objField is Guid) && objField.Equals(NullGuid));
            }
            return true;
        }

        public static object SetNull(PropertyInfo objPropertyInfo)
        {
            string refStringHelperL0 = objPropertyInfo.PropertyType.ToString();
            if (refStringHelperL0 == "System.Int16")
            {
                return NullShort;
            }
            if ((((refStringHelperL0 == "System.Int32") || (refStringHelperL0 == "System.Int64")) ? 1 : 0) != 0)
            {
                return NullInteger;
            }
            if (refStringHelperL0 == "System.Single")
            {
                return NullSingle;
            }
            if (refStringHelperL0 == "System.Double")
            {
                return NullDouble;
            }
            if (refStringHelperL0 == "System.Decimal")
            {
                return NullDecimal;
            }
            if (refStringHelperL0 == "System.DateTime")
            {
                return NullDate;
            }
            if ((((refStringHelperL0 == "System.String") || (refStringHelperL0 == "System.Char")) ? 1 : 0) != 0)
            {
                return NullString;
            }
            if (refStringHelperL0 == "System.Boolean")
            {
                return NullBoolean;
            }
            if (refStringHelperL0 == "System.Guid")
            {
                return NullGuid;
            }
            Type pType = objPropertyInfo.PropertyType;
            if (pType.BaseType.Equals(typeof(Enum)))
            {
                Array objEnumValues = Enum.GetValues(pType);
                Array.Sort(objEnumValues);
                return RuntimeHelpers.GetObjectValue(Enum.ToObject(pType, RuntimeHelpers.GetObjectValue(objEnumValues.GetValue(0))));
            }
            return null;
        }

        public static object SetNull(object objValue, object objField)
        {
            if (Information.IsDBNull(RuntimeHelpers.GetObjectValue(objValue)))
            {
                if (objField is short)
                {
                    return NullShort;
                }
                if (objField is int)
                {
                    return NullInteger;
                }
                if (objField is float)
                {
                    return NullSingle;
                }
                if (objField is double)
                {
                    return NullDouble;
                }
                if (objField is decimal)
                {
                    return NullDecimal;
                }
                if (objField is DateTime)
                {
                    return NullDate;
                }
                if (objField is string)
                {
                    return NullString;
                }
                if (objField is bool)
                {
                    return NullBoolean;
                }
                if (objField is Guid)
                {
                    return NullGuid;
                }
                return null;
            }
            return RuntimeHelpers.GetObjectValue(objValue);
        }

        public static bool NullBoolean
        {
            get
            {
                return false;
            }
        }

        public static DateTime NullDate
        {
            get
            {
                return DateTime.MinValue;
            }
        }

        public static decimal NullDecimal
        {
            get
            {
                return -79228162514264337593543950335M;
            }
        }

        public static double NullDouble
        {
            get
            {
                return double.MinValue;
            }
        }

        public static Guid NullGuid
        {
            get
            {
                return Guid.Empty;
            }
        }

        public static int NullInteger
        {
            get
            {
                return -1;
            }
        }

        public static short NullShort
        {
            get
            {
                return -1;
            }
        }

        public static float NullSingle
        {
            get
            {
                return float.MinValue;
            }
        }

        public static string NullString
        {
            get
            {
                return "";
            }
        }
    }
}

